<?php
include_once('common/header.php');
if($AppUI->id <= 0 || (isset($_SESSION['product']) && (($_SESSION['product']&1<<2) == 0))) {
	$this->_redirect(HOST_BACKEND);
}
$arrParams			= $objRequest->getParams();
$strRefer			= isset($arrParams['prefer']) ?  $arrParams['prefer'] : HOST_BACKEND . 'product/manufactory';
$intId				= isset($arrParams['pid']) ?  $arrParams['pid'] : 0;
$intLanguage		= isset($arrParams['planguage']) ?  $arrParams['planguage'] : LANGUAGE_VN;
$strName			= isset($arrParams['pname']) ?  $arrParams['pname'] : '';
$strCountry			= isset($arrParams['pcountry']) ?  $arrParams['pcountry'] : COUNTRY_DEFAULT;
$intProvince		= isset($arrParams['pprovince']) ?  $arrParams['pprovince'] : 0;
$intDistrict		= isset($arrParams['pdistrict']) ?  $arrParams['pdistrict'] : 0;
$strAddr			= isset($arrParams['paddr']) ?  $arrParams['paddr'] : '';
$strShort			= isset($arrParams['pshort']) ?  $arrParams['pshort'] : '';
$strContent			= isset($arrParams['pcontent']) ?  $arrParams['pcontent'] : '';
$oFile				= $_FILES['pimage'];
$strWebsite			= isset($arrParams['pwebsite']) ?  $arrParams['pwebsite'] : '';
$strTel				= isset($arrParams['ptel']) ?  $arrParams['ptel'] : '';
$strFax				= isset($arrParams['pfax']) ?  $arrParams['pfax'] : '';
$intError			= 0;
$strImage			= '';
if($intError == 0 && isset($oFile['name']) && $oFile['name'] != '') {
	$arrImage	= PhungTK_Upload::uploadProduct($oFile);
	if($arrImage['error'] == 0) {
		$strImage	= $arrImage['path'];
	}else {
		$intError 	= 5;
	}
}
if($intError == 0) {	
	if(isset($_SESSION['manupost'])) unset($_SESSION['manupost']);
	if(isset($_SESSION['manuerr'])) unset($_SESSION['manuerr']);
	$strName			= PhungTK_Function::stripTags($strName,-2);
	$strContent			= PhungTK_Function::stripTags($strContent,-1);
	$strShort			= ($strShort != '' && $strContent != '') ? PhungTK_Function::wordCut($strContent) : $strShort; 
	$strAddr			= PhungTK_Function::stripTags($strAddr,-2);
	$strWebsite			= PhungTK_Function::stripTags($strWebsite,-2);
	$strTel				= PhungTK_Function::stripTags($strTel,-2);
	$strFax				= PhungTK_Function::stripTags($strFax,-2);	
	$objManufactory 	= new Manufactory();
	$intError			= $objManufactory->update($AppUI->id, $intId, $strName, $strImage, $strShort, 
												  $strContent, $strAddr, $intDistrict, $intProvince, $strCountry, 
												  $strTel, $strFax, $strWebsite, $intLanguage);
	if($intError == 0) {				
		PhungTK_Function::setMsg($arrMessage[8]);
		$this->_redirect($strRefer);
	}
}
if($intError > 0) {
	$_SESSION['manupost']	= $objRequest->getParams();
	$_SESSION['manuerr']	= $arrError[$intError];
	$this->_redirect(HOST_BACKEND . 'product/manufactorye?id='.$intId);
}
?>